package cc.shimeng.fucloud.controller;

import cc.shimeng.fucloud.entity.Grade;
import cc.shimeng.fucloud.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/grades")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    @GetMapping
    public List<Grade> getAll() {
        return gradeService.findAll();
    }

    @GetMapping("/{id}")
    public Grade get(@PathVariable Integer id) {
        return gradeService.findById(id);
    }

    @PostMapping
    public Grade create(@RequestBody Grade grade) {
        return gradeService.save(grade);
    }

    @PutMapping("/{id}")
    public Grade update(@PathVariable Integer id, @RequestBody Grade grade) {
        return gradeService.save(grade);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        gradeService.deleteById(id);
    }
}